home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / DJLSR111.ZIP / libsrc / c / io / fwrite.c < prev    next >
C/C++ Source or Header  |  1993-06-28  |  1KB  |  56 lines

  1. /* This is file FWRITE.C */
  2. /* This file may have been modified by DJ Delorie (Jan 1991).  If so,
  3. ** these modifications are Coyright (C) 1993 DJ Delorie, 24 Kirsten Ave,
  4. ** Rochester NH, 03867-2954, USA.
  5. */
  6.  
  7. /*
  8.  * Copyright (c) 1980 Regents of the University of California.
  9.  * All rights reserved.  The Berkeley software License Agreement
  10.  * specifies the terms and conditions for redistribution.
  11.  */
  12.  
  13. #if defined(LIBC_SCCS) && !defined(lint)
  14. static char sccsid[] = "@(#)fwrite.c    5.2 (Berkeley) 3/9/86";
  15. #endif LIBC_SCCS and not lint
  16.  
  17. #include    <stdio.h>
  18.  
  19. fwrite(ptr, size, count, iop)
  20.     register const void *ptr;
  21.     int size, count;
  22.     register FILE *iop;
  23. {
  24.     register int s;
  25.  
  26.     s = size * count;
  27.     if (iop->_flag & _IOLBF)
  28.         while (s > 0) {
  29.             if (--iop->_cnt > -iop->_bufsiz && *(char *)ptr != '\n')
  30.                 *iop->_ptr++ = *(char *)ptr++;
  31.             else if (_flsbuf(*(unsigned char *)ptr++, iop) == EOF)
  32.                 break;
  33.             s--;
  34.         }
  35.     else while (s > 0) {
  36.         if (iop->_cnt < s) {
  37.             if (iop->_cnt > 0) {
  38.                 bcopy(ptr, iop->_ptr, iop->_cnt);
  39.                 ptr += iop->_cnt;
  40.                 iop->_ptr += iop->_cnt;
  41.                 s -= iop->_cnt;
  42.             }
  43.             if (_flsbuf(*(unsigned char *)ptr++, iop) == EOF)
  44.                 break;
  45.             s--;
  46.         }
  47.         if (iop->_cnt >= s) {
  48.             bcopy(ptr, iop->_ptr, s);
  49.             iop->_ptr += s;
  50.             iop->_cnt -= s;
  51.             return (count);
  52.         }
  53.     }
  54.     return (size != 0 ? count - ((s + size - 1) / size) : 0);
  55. }
  56.